package com.rxh.service.impl;

import com.rxh.mapper.base.IdMapper;
import com.rxh.mapper.core.CoreOrderMapper;
import com.rxh.mapper.merchant.*;
import com.rxh.pojo.base.SearchInfo;
import com.rxh.pojo.merchant.*;
import com.rxh.service.AcquirerService;
import com.rxh.service.ConstantService;
import com.rxh.service.MerchantService;
import com.rxh.utils.SystemConstant;
import com.rxh.utils.UUID;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * User: 陈俊雄
 * Date: 2018/3/21
 * Time: 14:48
 * Project: Management
 * Package: com.rxh.service.impl
 */
@Service
public class MerchantServiceImpl implements MerchantService {
    @Resource
    private MerchantInfoMapper merchantInfoMapper;
    @Resource
    private MerchantWebSiteMapper merchantWebSiteMapper;
    @Resource
    private MerchantPayMapper merchantPayMapper;
    @Resource
    private MerchantSettingMapper merchantSettingMapper;
    @Resource
    private MerchantWebsiteProTypeMapper merchantWebsiteProTypeMapper;
    @Resource
    private MerchantRateMapper merchantRateMapper;
    @Resource
    private MerchantUserMapper merchantUserMapper;
    @Resource
    private IdMapper idMapper;
    @Resource
    private CoreOrderMapper orderMapper;
    @Resource
    private ConstantService constantService;
    @Resource
    private AcquirerService acquirerService;

    @Override
    public Boolean isMerchantIdExist(Integer merId) {
        return merchantInfoMapper.selectByPrimaryKey(merId) != null;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_info", key = "'merchant_info'", condition = "#result == true"),
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting'", condition = "#result == true"),
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay'", condition = "#result == true")
    })
    @Override
    public Boolean addMerchant(Merchant merchant, String userName) {
        if (!addMerchantInfo(merchant.getMerchantInfo(), userName) &&
                !addMerchantSetting(merchant.getMerchantSetting()) &&
                !addMerchantPay(merchant.getMerchantPay())) {
            throw new RuntimeException("删除商户失败！");
        }
        return addMerchantInfo(merchant.getMerchantInfo(), userName) &&
                addMerchantSetting(merchant.getMerchantSetting()) &&
                addMerchantPay(merchant.getMerchantPay());
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_info", key = "'merchant_info'", condition = "#result == true"),
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting'", condition = "#result == true"),
            @CacheEvict(value = "merchant_pay", allEntries = true, condition = "#result == true"),
            @CacheEvict(value = "merchant_rate", allEntries = true, condition = "#result == true"),
            @CacheEvict(value = "merchant_web_site", allEntries = true, condition = "#result == true")
    })
    @Override
    public Boolean deleteMerchantById(Integer merchantId) {
        SearchInfo searchInfo = new SearchInfo();
        searchInfo.setMerId(merchantId);
        if (orderMapper.selectCountBySearchInfo(searchInfo) > 0) {
            return false;
        }
        // 删除商户网址扣率、商户网址支付信息、商户网址
        List<MerchantWebSite> merchantWebSiteList = selectAllMerchantWebSite()
                .stream()
                .filter(merchantWebSite -> merchantWebSite.getMerId().equals(merchantId))
                .collect(Collectors.toList());
        merchantWebSiteList.forEach(merchantWebSite -> {
            merchantRateMapper.deleteByRefIdAndRefType(merchantWebSite.getId(), SystemConstant.REF_TYPE_WEB);
            merchantPayMapper.deleteByRefIdAndRefType(merchantWebSite.getId(), SystemConstant.REF_TYPE_WEB);
            merchantWebSiteMapper.deleteByPrimaryKey(merchantWebSite.getId());
        });
        // 删除商户扣率、商户支付信息、商户设置、商户信息、商户用户
        merchantRateMapper.deleteByRefIdAndRefType(merchantId, SystemConstant.REF_TYPE_MERCHANT);
        merchantPayMapper.deleteByRefIdAndRefType(merchantId, SystemConstant.REF_TYPE_MERCHANT);
        merchantSettingMapper.deleteByPrimaryKey(merchantId);
        merchantInfoMapper.deleteByPrimaryKey(merchantId);
        merchantUserMapper.deleteByBelongTo(merchantId);
        return true;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_info", key = "'merchant_info'", condition = "#result == true"),
            @CacheEvict(value = "merchant_info", key = "'merchant_info:' + #merchant.merchantInfo.id", condition = "#result == true"),
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting'", condition = "#result == true"),
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay'", condition = "#result == true")
    })
    @Override
    public Boolean updateMerchant(Merchant merchant, String userName) {
        return updateMerchantInfo(merchant.getMerchantInfo(), userName) &&
                updateMerchantSetting(merchant.getMerchantSetting(), userName) &&
                updateMerchantPay(merchant.getMerchantPay(), userName);
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_info", key = "'merchant_info:' + #merchantInfo.id", condition = "#result == true"),
            @CacheEvict(value = "merchant_info", key = "'merchant_info'", condition = "#result == true")
    })
    @Override
    public Boolean addMerchantInfo(MerchantInfo merchantInfo, String userName) {
        merchantInfo.setCreator(userName);
        merchantInfo.setCreateTime(new Date());
        return merchantInfoMapper.insertSelective(merchantInfo) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_info", key = "'merchant_info:' + #merchantInfo.id", condition = "#result == true"),
            @CacheEvict(value = "merchant_info", key = "'merchant_info'", condition = "#result == true")
    })
    @Override
    public Boolean deleteMerchantInfo(MerchantInfo merchantInfo) {
        return merchantInfoMapper.deleteByPrimaryKey(merchantInfo.getId()) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_info", key = "'merchant_info:' + #merchantInfo.getId()", condition = "#result == true"),
            @CacheEvict(value = "merchant_info", key = "'merchant_info'", condition = "#result == true")
    })
    @Override
    public Boolean updateMerchantInfo(MerchantInfo merchantInfo, String userName) {
        merchantInfo.setModifier(userName);
        merchantInfo.setModifyTime(new Date());
        return merchantInfoMapper.updateByPrimaryKeySelective(merchantInfo) == 1;
    }

    @Cacheable(value = "merchant_info", key = "'merchant_info'")
    @Override
    public List<MerchantInfo> selectAllMerchantInfo() {
        return merchantInfoMapper.selectAll();
    }

    @Cacheable(value = "merchant_info", key = "#merchantId")
    @Override
    public MerchantInfo selectMerchantInfoByMerchantId(Integer merchantId) {
        return selectAllMerchantInfo().stream().filter(merchantInfo -> merchantInfo.getId().equals(merchantId)).findFirst().orElse(null);
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_rate", key = "'merchant_rate'", condition = "#result == true"),
            @CacheEvict(value = "merchant_rate", key = "'merchant_rate:' + #merchantRateList.get(0).getRefId().toString() + ':' + #merchantRateList.get(0).getRefType().toString()", condition = "#result == true")
    })
    @Override
    public Boolean updateMerchantRateByList(List<MerchantRate> merchantRateList, String userName) {
        Date date = new Date();
        merchantRateList.forEach(merchantRate -> {
            if (merchantRate.getId() == null) {
                merchantRate.setId(UUID.createIntegerKey(idMapper.selectLastId("merchant_rate")));
                merchantRate.setCreator(userName);
                merchantRate.setCreateTime(date);
                merchantRate.setStatus(SystemConstant.ENABLE);
                merchantRateMapper.insertSelective(merchantRate);
            } else {
                merchantRate.setModifier(userName);
                merchantRate.setModifyTime(date);
                merchantRateMapper.updateByPrimaryKeySelective(merchantRate);
            }
        });
        return true;
    }

    @Cacheable(value = "merchant_rate", key = "'merchant_rate:' + #refId.toString() + ':' + #refType.toString()")
    @Override
    public List<MerchantRate> getMerchantRateByRefIdAndRefType(Integer refId, Short refType) {
        return merchantRateMapper.selectByRefIdAndRefType(refId, refType);
    }

    @Cacheable(value = "merchant_rate", key = "'merchant_rate'")
    @Override
    public List<MerchantRate> selectAllMerchantRate() {
        return merchantRateMapper.selectAll();
    }

    @Cacheable(value = "merchant_web_site", key = "'merchant_web_site'")
    @Override
    public List<MerchantWebSite> selectAllMerchantWebSite() {
        return merchantWebSiteMapper.selectAll();
    }

    @Cacheable(value = "merchant_web_site", key = "#merchantId")
    @Override
    public List<MerchantWebSite> selectMerchantWebSiteByMerchantId(Integer merchantId) {
        return merchantWebSiteMapper.selectByMerchantId(merchantId);
    }

    @Override
    public Boolean isSiteUrlExist(String siteUrl) {
        return merchantWebSiteMapper.isSiteUrlExist(siteUrl);
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_web_site", allEntries = true, condition = "#result.size() != #idList.size()")
    })
    @Override
    public List<Integer> deleteMerchantWebSite(List<Integer> idList) {
        List<Integer> undeletable = new ArrayList<>();
        SearchInfo searchInfo = new SearchInfo();
        idList.forEach(integer -> {
            searchInfo.setSiteId(integer);
            if (orderMapper.selectCountBySearchInfo(searchInfo) == 0) {
                merchantRateMapper.deleteByRefIdAndRefType(integer, SystemConstant.REF_TYPE_WEB);
                merchantPayMapper.deleteByRefIdAndRefType(integer, SystemConstant.REF_TYPE_WEB);
                merchantWebSiteMapper.deleteByPrimaryKey(integer);
            } else {
                undeletable.add(integer);
            }
        });
        return undeletable;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_web_site", key = "'merchant_web_site'", condition = "#result == true"),
            @CacheEvict(value = "merchant_web_site", key = "'merchant_web_site:' + #merchantWebSite.getMerId()", condition = "#result == true")
    })
    @Override
    public Boolean addMerchantWebSite(MerchantWebSite merchantWebSite, String userName) {
        String a = idMapper.selectLastId("merchant_web_site");
        merchantWebSite.setId(UUID.createIntegerKey(idMapper.selectLastId("merchant_web_site")));
        merchantWebSite.setStatus(SystemConstant.WEB_SITE_STATUS_UNAUDITED);
        merchantWebSite.setCreator(userName);
        merchantWebSite.setCreateTime(new Date());
        return merchantWebSiteMapper.insertSelective(merchantWebSite) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_web_site", key = "'merchant_web_site'", condition = "#result == true"),
            @CacheEvict(value = "merchant_web_site", key = "'merchant_web_site:' + #merchantWebSite.getMerId()", condition = "#result == true")
    })
    @Override
    public Boolean updateMerchantWebSite(MerchantWebSite merchantWebSite, String userName) {
        merchantWebSite.setModifier(userName);
        merchantWebSite.setModifyTime(new Date());
        return merchantWebSiteMapper.updateByPrimaryKeySelective(merchantWebSite) == 1;
    }

    @Override
    public Map<String, Object> getMerchantSettingInit() {
        Map<String, Object> init = new HashMap<>();
        init.put("level", constantService.getConstantByGroupName(SystemConstant.LEVEL));
        init.put("automaticRenewal", constantService.getConstantByGroupName(SystemConstant.AUTOMATIC_RENEWAL));
        init.put("trackSetting", constantService.getConstantByGroupName(SystemConstant.TRACK_SETTING));
        init.put("trackAudit", constantService.getConstantByGroupName(SystemConstant.TRACK_AUDIT));
        init.put("correctDistribute", constantService.getConstantByGroupName(SystemConstant.CORRECT_DISTRIBUTE));
        init.put("currency", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.CURRENCY));
        return init;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting' + #merchantSetting.getRefId() + ':' + #merchantSetting.getRefType()", condition = "#result == true"),
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting'", condition = "#result == true")
    })
    @Override
    public Boolean addMerchantSetting(MerchantSetting merchantSetting) {
        return merchantSettingMapper.insertSelective(merchantSetting) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting' + #merchantSetting.getRefId() + ':' + #merchantSetting.getRefType()", condition = "#result == true"),
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting'", condition = "#result == true")
    })
    @Override
    public Boolean deleteMerchantSetting(MerchantSetting merchantSetting) {
        return merchantSettingMapper.deleteByPrimaryKey(merchantSetting.getId()) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting' + #merchantSetting.getRefId() + ':' + #merchantSetting.getRefType()", condition = "#result == true"),
            @CacheEvict(value = "merchant_setting", key = "'merchant_setting'", condition = "#result == true")
    })
    @Override
    public Boolean updateMerchantSetting(MerchantSetting merchantSetting, String userName) {
        merchantSetting.setModifier(userName);
        merchantSetting.setModifyTime(new Date());
        return merchantSettingMapper.updateByPrimaryKeySelective(merchantSetting) == 1;
    }

    @Cacheable(value = "merchant_setting", key = "'merchant_setting'")
    @Override
    public List<MerchantSetting> selectAllMerchantSetting() {
        return merchantSettingMapper.selectAll();
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay:' + #merchantPay.getId() + ':' + #merchantPay.getRefType()", condition = "#result == true"),
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay'", condition = "#result == true")
    })
    @Override
    public Boolean addMerchantPay(MerchantPay merchantPay) {
        merchantPay.setId(UUID.createIntegerKey(idMapper.selectLastId("merchant_pay")));
        merchantPay.setStatus(SystemConstant.DISABLE);
        return merchantPayMapper.insertSelective(merchantPay) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay:' + #merchantPay.getId() + ':' + #merchantPay.getRefType()", condition = "#result == true"),
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay'", condition = "#result == true")
    })
    @Override
    public Boolean deleteMerchantPay(MerchantPay merchantPay) {
        return merchantPayMapper.deleteByPrimaryKey(merchantPay.getId()) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay:' + #merchantPay.getId() + ':' + #merchantPay.getRefType()", condition = "#result == true"),
            @CacheEvict(value = "merchant_pay", key = "'merchant_pay'", condition = "#result == true")
    })
    @Override
    public Boolean updateMerchantPay(MerchantPay merchantPay, String userName) {
        merchantPay.setModifier(userName);
        merchantPay.setModifyTime(new Date());
        return merchantPayMapper.updateByPrimaryKeySelective(merchantPay) == 1;
    }

    @Cacheable(value = "merchant_pay", key = "#refId + ':' + #refType")
    @Override
    public MerchantPay selectMerchantPayByRefIdAndRefType(Integer refId, Short refType) {
        return selectAllMerchantPay().stream().filter(merchantPay -> merchantPay.getRefId().equals(refId) &&
                merchantPay.getRefType().equals(refType)).findFirst().orElse(null);
    }

    @Cacheable(value = "merchant_pay", key = "'merchant_pay'")
    @Override
    public List<MerchantPay> selectAllMerchantPay() {
        return merchantPayMapper.selectAll();
    }

    @Override
    public Map<String, Object> getAllMerchantInfoForView() {
        Map<String, Object> merchantInfo = new HashMap<>();
        merchantInfo.put("merchantInfo", selectAllMerchantInfo());
        merchantInfo.put("merchantSetting", selectAllMerchantSetting());
        merchantInfo.put("merchantPay", selectAllMerchantPay());
        return merchantInfo;
    }

    @Override
    public Map<String, Object> getMgmtInit() {
        Map<String, Object> init = new HashMap<>();
        init.put("merchantCategory", constantService.getConstantByGroupName(SystemConstant.MERCHANT_CATEGORY));
        init.put("businessType", constantService.getConstantByGroupName(SystemConstant.BUSINESS_TYPE));
        init.put("merchantStatus", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.MERCHANT_STATUS));
        return init;
    }

    @Override
    public Map<String, Object> getMerchantPayInit() {
        Map<String, Object> init = new HashMap<>();
        init.put("acquirer", acquirerService.selectAllEnableAcquirer());
        init.put("acquirerAccount", acquirerService.selectAllEnableAcquirerAccount());
        init.put("currency", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.CURRENCY));
        init.put("encrypt", constantService.getConstantByGroupName(SystemConstant.ENCRYPT));
        init.put("status", constantService.getConstantByGroupName(SystemConstant.STATUS));
        init.put("payMode", constantService.getConstantByGroupName(SystemConstant.PAY_MODE));
        init.put("interfaceType", constantService.getConstantByGroupName(SystemConstant.INTERFACE_TYPE));
        init.put("Credit", constantService.getConstantByGroupName(SystemConstant.CREDIT));
        init.put("Debit", constantService.getConstantByGroupName(SystemConstant.DEBIT));
        init.put("Yandex", constantService.getConstantByGroupName(SystemConstant.YANDEX));
        init.put("Qiwi", constantService.getConstantByGroupName(SystemConstant.QIWI));
        init.put("Remittance", constantService.getConstantByGroupName(SystemConstant.REMITTANCE));
        return init;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_website_pro_type", allEntries = true, condition = "#result == true")
    })
    @Override
    public Boolean addMerchantWebsiteProType(MerchantWebsiteProType merchantWebsiteProType, String userName) {
        merchantWebsiteProType.setId(UUID.createKey("merchant_website_pro_type"));
        merchantWebsiteProType.setCreateTime(new Date());
        merchantWebsiteProType.setCreateUser(userName);
        return merchantWebsiteProTypeMapper.insertSelective(merchantWebsiteProType) == 1;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_website_pro_type", allEntries = true, condition = "#result.size() != #idList.size()")
    })
    @Override
    public List<Long> deleteMerchantWebsiteProType(List<Long> idList) {
        List<Long> undeletable = new ArrayList<>();
        idList.forEach(aLong -> {
            if (merchantWebsiteProTypeMapper.selectCountByMerchantWebsiteProType(aLong) == 0) {
                merchantWebsiteProTypeMapper.deleteByPrimaryKey(aLong);
            } else {
                undeletable.add(aLong);
            }
        });
        return undeletable;
    }

    @Caching(evict = {
            @CacheEvict(value = "merchant_website_pro_type", allEntries = true, condition = "#result == true")
    })
    @Override
    public Boolean updateMerchantWebsiteProType(MerchantWebsiteProType merchantWebsiteProType, String userName) {
        merchantWebsiteProType.setModifyTime(new Date());
        merchantWebsiteProType.setModifyUser(userName);
        return merchantWebsiteProTypeMapper.updateByPrimaryKeySelective(merchantWebsiteProType) == 1;
    }

    @Cacheable(value = "merchant_website_pro_type", key = "'merchant_website_pro_type'")
    @Override
    public List<MerchantWebsiteProType> selectAllMerchantWebsiteProType() {
        return merchantWebsiteProTypeMapper.selectAll();
    }

    @Override
    public Map<String, Object> getWebSiteInit() {
        Map<String, Object> init = new HashMap<>();
        init.put("merchantInfo", selectAllMerchantInfo());
        init.put("merchantWebSite", selectAllMerchantWebSite());
        init.put("merchantWebsiteProType", selectAllMerchantWebsiteProType());
        init.put("industryType", constantService.getConstantByGroupName(SystemConstant.INDUSTRY_TYPE));
        init.put("webSiteStatus", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.MERCHANT_STATUS));
        return init;
    }

    @Override
    public Map<String, Object> getMerchantWebSiteInit(Integer merchantId) {
        Map<String, Object> init = new HashMap<>();
        init.put("industryType", constantService.getConstantByGroupName(SystemConstant.INDUSTRY_TYPE));
        init.put("webSiteStatus", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.MERCHANT_STATUS));
        return init;
    }

    @Override
    public Map<String, Object> getQuickTestInit() {
        Map<String, Object> init = new HashMap<>();
        init.put("merchantInfo", selectAllMerchantInfo());
        init.put("merchantPay", selectAllMerchantPay());
        init.put("currency", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.CURRENCY));
        init.put("lang", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.LANG));
        init.put("payMode", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.PAY_MODE));
        init.put("Credit", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.CREDIT));
        init.put("Debit", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.DEBIT));
        init.put("Yandex", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.YANDEX));
        init.put("Qiwi", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.QIWI));
        init.put("Remittance", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.REMITTANCE));
        init.put("country", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.COUNTRY));
        init.put("crossPayURL", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.QUICK_TEST));
        init.put("inlinePayURL", constantService.getConstantByGroupNameAndSortValueIsNULL(SystemConstant.QUICK_TEST));
        return init;
    }

    @Override
    public Map<String, Object> getMerchantSettingInit(Integer merchantId) {
        Map<String, Object> init = new HashMap<>();
        init.put("merchantSetting", merchantSettingMapper.selectByRefId(merchantId));
        init.put("trackSetting", constantService.getConstantByGroupName(SystemConstant.TRACK_SETTING));
        init.put("trackAudit", constantService.getConstantByGroupName(SystemConstant.TRACK_AUDIT));
        init.put("correctDistribute", constantService.getConstantByGroupName(SystemConstant.CORRECT_DISTRIBUTE));
        init.put("currency", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.CURRENCY));
        return init;
    }

    @Override
    public Map<String, Object> getMerchantRateInit(Integer merchantId) {
        Map<String, Object> init = new HashMap<>();
        // init.put("currency", constantService.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.CURRENCY));
        init.put("merchantRate", merchantRateMapper.selectByRefIdAndRefTypeForMerchantWeb(merchantId, SystemConstant.REF_TYPE_MERCHANT));
        init.put("merchantPay", merchantPayMapper.selectByRefIdAndRefTypeForMerchantWeb(merchantId, SystemConstant.REF_TYPE_MERCHANT));
        init.put("encrypt", constantService.getConstantByGroupName(SystemConstant.ENCRYPT));
        init.put("status", constantService.getConstantByGroupName(SystemConstant.STATUS));
        init.put("payMode", constantService.getConstantByGroupName(SystemConstant.PAY_MODE));
        init.put("Credit", constantService.getConstantByGroupName(SystemConstant.CREDIT));
        init.put("Debit", constantService.getConstantByGroupName(SystemConstant.DEBIT));
        init.put("Yandex", constantService.getConstantByGroupName(SystemConstant.YANDEX));
        init.put("Qiwi", constantService.getConstantByGroupName(SystemConstant.QIWI));
        init.put("Remittance", constantService.getConstantByGroupName(SystemConstant.REMITTANCE));
        return init;
    }


}